package me.zhengjie.utils;


import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class CircleRing {
    public static void main(String[] args) {
        // 创建一个透明背景的图片
        int width = 800;
        int height = 800;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = image.createGraphics();

        // 设置抗锯齿以提高图像质量
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

                // 设置渐变颜色
        Color startColor = new Color(255, 255, 240); // 浅橙色
        Color endColor = new Color(246, 208, 194);
        // 设置透明颜色
        GradientPaint gradient = new GradientPaint(0, 0, startColor,
                width / 2, height / 2, endColor,
                true);
        g2d.setPaint(gradient);

        // 画外圆
        int xCenter = width / 2;
        int yCenter = height / 2;
        int outerRadius = 400; // 外半径
        int innerRadius = 380; // 内半径
        g2d.fillOval(xCenter - outerRadius, yCenter - outerRadius, 2 * outerRadius, 2 * outerRadius);

        // 设置透明色，用于绘制内圆
        g2d.setComposite(AlphaComposite.Clear);
        g2d.fillOval(xCenter - innerRadius, yCenter - innerRadius, 2 * innerRadius, 2 * innerRadius);
        g2d.setComposite(AlphaComposite.SrcOver);

        g2d.dispose();

        try {
            ImageIO.write(image, "jpg", new File("D:\\360Downloads\\circle_ring.jpg"));
            System.out.println("Image saved successfully!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
